import Vue from 'vue'
import VueRouter from 'vue-router'
import delView from '../views/delView.vue'
import welcomeView from '../views/Login/welcomeView.vue'
import marking from './moudels/marking.js'
import wzz from './moudels/wzz.js'
import setting from './moudels/setting.js'
import wq from './moudels/wq.js'
import rsq from './moudels/rsq.js'
import jxj from './moudels/jxj.js'
import lt from './moudels/lt.js'
import gl from './moudels/gl.js'
import lgm from './moudels/lgm.js'
Vue.use(VueRouter)
const routes = [
    ...marking,
    ...wzz,
    ...setting,
    ...wq,
    ...rsq,
    ...jxj,
    ...lt,
    ...gl,
    ...lgm,
    {
        // 登录页
        path: '/',
        name: 'welcome',
        component: welcomeView
    },
    {
        // 协议提示
        path: '/ProtocolReading',
        name: 'ProtocolReading',
        component: () => import('../views/Login/ProtocolReading.vue')
    },
    {
        // 用户协议
        path: '/userAgreement',
        name: 'userAgreement',
        component: () => import('../views/Login/UserAgreement.vue')
    },
    {
        // 隐私政策
        path: '/PrivacyPolicy',
        name: 'PrivacyPolicy',
        component: () => import('../views/Login/PrivacyPolicy.vue')
    },
    {
        // 验证码登录
        path: '/captchaLogin',
        name: 'captchaLogin',
        component: () => import('../views/Login/captchaLogin.vue')
    },
    {
        // 账号密码登录
        path: '/UserPwdLogin',
        name: 'UserPwdLogin',
        component: () => import('../views/Login/UserPwdLogin.vue')
    },
    {
        // 号码区号选择GetVerificationCode
        path: '/SelectTel',
        name: 'SelectTel',
        component: () => import('../components/SelectTel.vue')
        // component: () => import('../components/CountryCode.vue')
    },
    {
        // 短信验证
        path: '/GetVerificationCode',
        name: 'GetVerificationCode',
        component: () => import('../views/Login/GetVerificationCode.vue')
    },
    {
        //重置密码
        path: '/ResetPassword/:number',
        name: 'ResetPassword',
        component: () => import('../views/Login/ResetPassword.vue')
    },
    {
        //重置新密码
        path: '/SettingNewPwd',
        name: 'SettingNewPwd',
        component: () => import('../views/Login/SettingNewPwd.vue')
    },
    {
        path: '/tar',
        name: 'tar',
        component: () => import('../views/HomeView/TarView.vue'),
        children:[
            {
                path: '',
                name: 'homepage',
                component: () => import('../views/homepage/Home.vue')
              },
              {
                path: 'homepage',
                name: 'homepage',
                component: () => import('../views/homepage/Home.vue')
              },
              {
                path: 'undoneOrders',
                name: 'undoneOrders',
                component: () => import('../views/undoneOrders/undoneOrders')
              },
              {
                path: 'historyOrders',
                name: 'historyOrders',
                component: () => import('../views/historyOrders/historyOrders')
              },
              {
                path: 'meView',
                name: 'meView',
                component: () => import('../views/historyOrders/meView')
              },
        ]
    },
    {
        path: '*',
        name: 'delView',
        component: delView
    },
    
]

const router = new VueRouter({
    base: process.env.BASE_URL,
    mode: 'history',
    routes
})

// 根据访问的路径中 auth 是否为 true
// 路由守卫 - 登录拦截
// router.beforeEach((to, from, next) => {
//     // const token = store.state.token // 表示用户登录的凭证
//     // const token = localStorage.getItem(token)
//     if (to.meta.auth) {
//         // 如果路由中的 meta 字段下的 auth 为true，表示该路由必须登录后访问
//         if (token) {
//             // token 存在，表示已经登陆了，那么想干嘛干嘛去
//             next()
//         } else {
//             // 不存在，表明你没有登录，不好意思，回到登录页
//             // next('/loginView')
//         }
//     } else {
//         // 不需要登录就可以访问
//         next() // 直接下一步
//     }
// })

export default router
